/*! 
 * jquery.event.drop.modes - v 2.0.0 - http://jquery-ux.com/
 * Copyright (c) 2010 Michael Helgeson, Three Dub Media
 * Open Source MIT License - http://jquery-ux.com/license 
 */
// Created: 2010-01-19 
// Updated: 2010-01-19
// REQUIRES: jquery 1.3+, jquery.event.drop

;(function($){ // secure $ jQuery alias

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// priority to nested child elements
$.event.special.drop.modes['childfirst'] = function( event, proxy, target ){
	var best = ( this.best || {} ).elem;	
	// the cursor is within the element... 
	if ( this.contains( target, [ event.pageX, event.pageY ] ) ){
		// first element found	
		if ( !target.elem || !best ) this.best = target; 
		// take the child element or keep the previous best
		else this.best = ( // comparison logic
			best.contains ? best != target.elem && best.contains( target.elem ) : 
				!!( best.compareDocumentPosition( target.elem ) & 16 ) 
			) ? target : this.best;
		}
	// no direct winner
	return null; 
	};
// set the default tolerance to the new mode
// jQuery.event.special.drop.mode = 'childfirst';

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// priority to higher z-indexes...
$.event.special.drop.modes['z-index'] = function( event, proxy, target ){
	var best = ( this.best || {} ).elem;	
	// the cursor is within the element... 
	if ( this.contains( target, [ event.pageX, event.pageY ] ) ){
		// first element found	
		if ( !target.elem || !best ) this.best = target; 
		// take the child element or keep the previous best
		else this.best = ( 
			parseInt( $( best ).css("z-index") || "0" ) < parseInt( $( target.elem ).css("z-index") || "0" )
			) ? target : this.best;
		}
	// no direct winner
	return null; 
	};
// set the default tolerance to the new mode
// jQuery.event.special.drop.mode = 'z-index';

})(jQuery); // confine scope